home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / WHIZZARD.LZH / QPRINT.ASM < prev    next >
Assembly Source File  |  1984-07-12  |  7KB  |  257 lines

  1. COMMENT *
  2.  
  3.                  CLUBware  (tm)
  4.  
  5.       QPRINT prints a character string on the screen starting
  6.           at the current cursor position.  After the string is
  7.           written to the screen the cursor position is updated
  8.           to just after the string.
  9.  
  10.            Copyright 1984 Rayhawk Automation N.W. Inc
  11.                   P.O. Box 1427
  12.                   Beaverton, Oregon   97075
  13.  
  14.       Algorithm:
  15.           1) load type of crt display from 0000:463
  16.           2) load current position from 0000:0450
  17.           3) load count of characters to write
  18.           4) load string address
  19.           5) address the screen segment
  20.           6) move string to screen segment while synchronizing
  21.               with horizontal retrace
  22.           7) update cursor position
  23.  
  24.  
  25.       CALL    QPRINT ( FLAG% , CHARACTER$ )
  26.  
  27.           FLAG%       environment flag
  28.                   = 0 means under basic interpreter
  29.                   = 1 means under compiled basic not /O
  30.                   = 2 means under compiled basic with /O
  31.                   = 3 means under compiled business basic
  32.  
  33.           CHARACTER$  character string to write to screen
  34.  
  35.                                           *
  36.  
  37. ;______________________________________________________________________________
  38.  
  39. ;  Normal assembly directives
  40.  
  41. CODE      SEGMENT PARA PUBLIC 'CODE'
  42.  
  43.       ASSUME  CS:CODE
  44.  
  45.       EXTRN   $PUTCPOS:FAR
  46.  
  47.       PUBLIC  QPRINT
  48.  
  49. STRING_DESC      EQU  WORD PTR [BP+6] ; address of string descriptor on stack
  50.  
  51. ENV_FLAG      EQU  WORD PTR [BP+8] ; address of environment flag on stack
  52.  
  53. ;______________________________________________________________________________
  54.  
  55. QPRINT      PROC      FAR
  56.  
  57.       PUSH      BP               ; address parameters on stack
  58.       MOV      BP,SP
  59.  
  60.       PUSH      AX               ; save all registers used,
  61.       PUSH      BX
  62.       PUSH      CX
  63.       PUSH      DX
  64.       PUSH      DI
  65.       PUSH      SI
  66.       PUSH      ES
  67.  
  68.  
  69. ;      ...      0) load environment flag showing compiled or interpreted
  70.  
  71.       MOV      SI,ENV_FLAG           ; load address of environment flag
  72.       MOV      SI,WORD PTR [SI]     ; load flag itself
  73.  
  74.  
  75.  
  76. ;      ...      1) load type of crt display from 0000:463
  77.  
  78.       SUB      AX,AX              ; address system area
  79.       MOV      ES,AX
  80.  
  81.       MOV      DX,WORD PTR ES:[463h]      ; load address of display adapter
  82.       ADD      DX,6                 ; address crt status port
  83.  
  84.  
  85.  
  86. ;      ...      2) load current position from 0000:0450 if compiled
  87. ;              or from DS:[0056h] if interpreted
  88.  
  89.       CMP      SI,0               ; check environment flag
  90.       JNE      COMPILED
  91.  
  92.       MOV      CX,WORD PTR DS:[0056h]   ; load from basic space
  93.       XCHG      CL,CH            ; basic has it reversed
  94.       DEC      CL               ; basic starts count from 1
  95.       DEC      CH               ;  instead of zero
  96.       JMP      SHORT CALC_POSITION
  97.  
  98. COMPILED:
  99.       MOV      CX,WORD PTR ES:[450h]    ; load current position
  100.                        ;  from system space
  101. CALC_POSITION:
  102.       SUB      AH,AH            ; isolate row number in AX
  103.       MOV      AL,CH
  104.       MOV      BL,80            ; multiply row by 80 bytes per row
  105.       MUL      BL
  106.       SUB      CH,CH            ; add in column number
  107.       ADD      AX,CX
  108.  
  109.       MOV      DI,AX
  110.       SHL      DI,1               ; multiply by 2 to account
  111.                        ;  for attribute bytes
  112.  
  113. ;      ...      3) load count of characters to write
  114. ;             only 1 byte if interpreted
  115. ;              2 bytes if compiled
  116.  
  117.       MOV      BX,STRING_DESC       ; load address of string descriptor
  118.  
  119.       CMP      SI,0               ; running compiled?
  120.       JNE      NOT_INTERPRETED
  121.  
  122.       MOV      CL,BYTE PTR [BX]     ; load 1 byte count itself
  123.       SUB      CH,CH
  124.       INC      BX               ; bump to string address
  125.       JMP      SHORT LOAD_ADDRESS
  126.  
  127. NOT_INTERPRETED:
  128.       MOV      CX,WORD PTR [BX]     ; load 2 byte count itself
  129.       ADD      BX,2               ; bump to string address
  130.  
  131. LOAD_ADDRESS:
  132.  
  133. ;      ...      4) load string address
  134. ;               next two bytes if normal compiled
  135. ;            three bytes past if in business basic
  136.  
  137.       MOV      BX,WORD PTR [BX]     ; load offset of string
  138.  
  139.       CMP      SI,3
  140.       JNE      NOT_BUSINESS
  141.  
  142.       ADD      BX,3               ;  Support BBC String format
  143.  
  144. NOT_BUSINESS:
  145.  
  146.       MOV      SI,BX            ; move offset over
  147.       MOV      BH,07h           ; use normal video attribute
  148.  
  149.  
  150. ;      ...      5) address the screen segment
  151.  
  152.       MOV      AX,0B000h           ; screen seg for monochrome card
  153.       CMP      DX,03DAh           ; is this a graphic card?
  154.       JNE      MONOCHROME
  155.  
  156.       MOV      AX,0B800h           ; load screen seg for graphic card
  157.  
  158. MONOCHROME:
  159.  
  160.       MOV      ES,AX            ; address the screen buffer
  161.  
  162.  
  163. ;      ...      6) move string to screen while synchronizing
  164. ;              with horizontal retrace
  165.  
  166. DISPLAY_LOOP:
  167.       LODSB                ; load next character
  168.       MOV      BL,AL
  169.  
  170.       CLI
  171. HSYNC_WAIT1:
  172.       IN      AL,DX            ; check for horizontal retrace
  173.       TEST      AL,1
  174.       JNZ      HSYNC_WAIT1           ; wait for retrace
  175. HSYNC_WAIT2:
  176.       IN      AL,DX            ; check for horizontal retrace
  177.       TEST      AL,1
  178.       JZ      HSYNC_WAIT2           ; wait for retrace
  179.  
  180.       MOV      AX,BX
  181.       STOSW                ; store character and attribute
  182.       STI
  183.  
  184.       CMP      DI,4000
  185.       JL      NOT_OFF_PAGE
  186.       MOV      DI,0               ; start at top again
  187. NOT_OFF_PAGE:
  188.  
  189.       LOOP      DISPLAY_LOOP           ; repeat cx times
  190.  
  191.  
  192. ;      ...      7) update cursor position
  193.  
  194.       MOV      AX,DI            ; load current position
  195.       SHR      AX,1               ; discount attribute bytes
  196.       SUB      DX,DX            ; no sign in this division
  197.       MOV      BX,80            ; divide by nmbr of chars per row
  198.       DIV      BX
  199.       MOV      DH,AL            ; store row number
  200.                        ; column number already in DL
  201.       MOV      BH,0               ; assume page 0
  202.       MOV      AH,2               ; request new position
  203.       INT      10h
  204.  
  205.       XCHG      DH,DL            ; basic likes it reversed
  206.       INC      DL               ; basic starts count from 1
  207.       INC      DH               ;  instead of zero
  208.  
  209.       MOV      SI,ENV_FLAG           ; load address of environment flag
  210.       CMP      WORD PTR DS:[SI],0   ; examine flag
  211.       JE      NOT_COMPILED
  212.  
  213.       CMP      WORD PTR DS:[SI],3   ; business basic?
  214.       JE      RET_TO_BASIC
  215.  
  216.       CMP      WORD PTR DS:[SI],2   ; compiled with /O?
  217.       JE      WITH_SLASH_O
  218.  
  219.                                     ; FLAG = 1
  220.       MOV      WORD PTR DS:[87h],DX ; store screen address
  221.       JMP      SHORT RET_TO_BASIC
  222.  
  223.  
  224. WITH_SLASH_O:                                ; FLAG = 2
  225.       MOV      DI,SEG $PUTCPOS     ; address put cursor routine
  226.       MOV      ES,DI
  227.       MOV      DI,OFFSET $PUTCPOS
  228.       MOV      DI,WORD PTR ES:[DI+2]  ; load offset of cursor storage
  229.       MOV      WORD PTR DS:[DI],DX     ; store new cursor position
  230.       JMP      SHORT RET_TO_BASIC
  231.  
  232.  
  233. NOT_COMPILED:                                ; FLAG = 0
  234.       MOV      WORD PTR DS:[0056h],DX ; store new cursor position
  235.  
  236.  
  237. RET_TO_BASIC:                                ; FLAG = 3
  238.  
  239.       POP      ES
  240.       POP      SI
  241.       POP      DI
  242.       POP      DX
  243.       POP      CX
  244.       POP      BX
  245.       POP      AX
  246.       POP      BP
  247.       RET      4
  248.  
  249.  
  250. QPRINT      ENDP
  251.  
  252. ;______________________________________________________________________________
  253.  
  254. CODE      ENDS
  255.  
  256.       END
  257.